﻿using System;
using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Daemon.CSharp.Stages;
using JetBrains.ReSharper.Daemon.Stages;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.CSharp.Tree;
using Twins.Classes;

namespace Twins.Daemon
{
    public class TwinsStageProcess : CSharpDaemonStageProcessBase
    {
        private readonly DispatherProject project;
        private bool flag = true;

        public TwinsStageProcess(IDaemonProcess process, DispatherProject project) : base(process)
        {
            this.project = project;
        }

        public override void Execute(Action<DaemonStageResult> commiter)
        {
            HighlightInFile((file, consumer) => file.ProcessDescendants(this, consumer), commiter);
        }

        public override void VisitCSharpNamespaceDeclaration(ICSharpNamespaceDeclaration cSharpNamespaceDeclarationParam, IHighlightingConsumer consumer)
        {
            if (flag)
            {
                flag = false;
                project.LookCSharpFile(consumer, ((TwinsStageProcess)consumer.Process).File);
            }
            base.VisitCSharpNamespaceDeclaration(cSharpNamespaceDeclarationParam, consumer);
        }
    }
}